from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from config.config import HOST
'''添加应收款页面'''


class AddCreditPage(BasePage):
    # 添加应收款成功的提示语定位
    url='http://{}/crm/index.php?m=finance'.format(HOST)
    add_credit_tips_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    # 应收款名定位
    credit_name_locator = (By.NAME, "name")
    # 客户定位
    customer_name_locator = (By.NAME, "customer")
    # 选择客户定位
    select_customer_locater = (By.XPATH, '//*[@id="datas"]/tr/td[1]/input[1]')
    # 选择客户，点击确定
    customer_ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')
    # 收款金额定位
    credit_price_locator = (By.ID, "price")
    # 添加应收款确定定位
    addcredit_confirm_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)')
    # 添加应收款，取消按钮定位
    addcredit_cancel_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[3]')

    def input_credit_name(self,credit_name):
        '''输入应收款名'''
        self.driver.find_element(*self.credit_name_locator).send_keys(credit_name)

    def click_customer_name(self):
        '''点击客户'''
        self.driver.find_element(*self.customer_name_locator).click()

    def select_customer(self):
        '''在弹出来的客户选择框选择第一个客户'''
        self.driver.find_element(*self.select_customer_locater).click()

    def click_customer_ok(self):
        '''点击客户选择框的ok按钮'''
        self.driver.find_element(*self.customer_ok_locator).click()

    def input_credit_price(self,price):
        '''输入收款金额'''
        self.driver.find_element(*self.credit_price_locator).send_keys(price)

    def click_add_credit_confirm(self):
        '''点击添加应收款的确定按钮'''
        self.driver.find_element(*self.addcredit_confirm_locator).click()

    def click_add_credit_cancel(self):
        '''点击添加应收款的取消按钮'''
        self.driver.find_element(*self.addcredit_cancel_locator).click()


    def get_add_credit_url(self):
        '''获取添加应收款页面的url'''
        return self.current_url()

    def get_add_credit_tips(self):
        """获取登录成功的提示语"""
        tips = self.driver.find_element(*self.add_credit_tips_locator).text
        return tips